<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class MKhuyenmai extends CI_Model{
    private $makm;
    private $tenkm;
    private $noidung;
    private $hinhanh;
    private $tgbatdau;
    private $tgketthuc;
    public function __construct() {
        parent::__construct();
        $this->load->database();
        $this->OnCreate();
    }
    public function OnCreate(){
        $this->makm = "";
        $this->tenkm = "";
        $this->noidung="";
        $this->hinhanh="";
        $this->tgbatdau="";
        $this->tgketthuc="";
    }
     public function set_makm($data) {
        $this->makm = $data;
    }
    public function set_tenkm($data) {
        $this->tenkm = $data;
    }
    public function set_noidung($data) {
        $this->noidung = $data;
    }
    public function set_hinhanh($data) {
        $this->hinhanh = $data;
    }
    public function set_tgbatdau($data) {
        $this->tgbatdau = $data;
    }
    public function set_tgketthuc($data) {
        $this->tgketthuc = $data;
    }
    //////////////////////////////
    public function get_makm() {
        return $this->makm;
    }
    public function get_tenkm() {
        return $this->tenkm;
    }
    public function get_noidung() {
        return $this->noidung;
    }
    public function get_hinhanh() {
        return $this->hinhanh;
    }
    public function get_tgbatdau() {
        return $this->tgbatdau;
    }
    public function get_tgketthuc() {
        return $this->tgketthuc;
    }
//////////////////////////
    public function Save() {
        $data = array("makm" => $this->makm, "tenkm" => $this->tenkm, "noidung" => $this->noidung, "hinhanh" => $this->hinhanh, "tgbatdau" => $this->tgbatdau,"tgketthuc"=>  $this->tgketthuc);
        $this->db->insert("taikhoan", $data);
    }

    public function UpdateField($strWhere) {
        $arr = array();
        $arr["makm"] = $this->makm;
        $arr["tenkm"] = $this->tenkm;
        $arr["noidung"] = $this->noidung;
        $arr["hinhanh"] = $this->hinhanh;
        $arr["tgbatdau"] = $this->tgbatdau;
        $arr["tgketthuc"] = $this->tgketthuc;
        
        if (!empty($strWhere)) {
            $this->db->where($strWhere,NULL,TRUE);
        }
        $this->db->update("khuyenmai", $arr);
    }

    public function Delete($strWhere = NULL) {
        if (!is_null($strWhere)) {
            $this->db->where($strWhere, NULL, FALSE);
            $this->db->delete("khuyenmai");
        }
        else
            $this->db->empty_table('khuyenmai');
    }
    public function get_top_id() {
        $Query = $this->db->query("select * from khuyenmai");
        $dem = $Query->num_rows();
        return ($dem);
    }
    public function getOject($strWhere) {
        //$this->Oncreate();
         $this->db->from("khuyenmai");
         $this->db->where($strWhere);
        // $this->db->join('loaitk', 'taikhoan.loaitk=loaitaikhoan.loaitk');
         $query =  $this->db->get();
        $ar = $query->row_array();
        if (!empty($ar)) {
            $this->makm = $ar["makm"];
            $this->tenkm = $ar["tenkm"];
            $this->noidungu = $ar["noidung"];
            $this->hinhanh = $ar["hinhanh"];
             $this->tgbatdau = $ar["tgbatdau"];
            $this->tgketthuc = $ar["tgketthuc"];
        }
        return $ar;
    }
}
?>
